﻿<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
class SCTV_RequirementInstall extends ModuleInstall {
    public function install() { // Here you can place the installation process for the module
    	Utils_CommonDataCommon::new_array('SCTV/Requirement/Status',array(_M('In Progress'),_M('Completed'),_M('Canceled')), true,true);
		Utils_CommonDataCommon::new_array('SCTV/Requirement/Todo',array(_M('Task of business'),_M('Task of technical'),_M('Task of accountant')), true,true);
	
		Base_ThemeCommon::install_default_theme($this->get_type());
				
		$fields = array(			
			array('name'=>_M('Customer Group'), 'type'=>'select', 'param'=>array('SCTV_CustomerGroup'=>'Name'), 'required'=>true, 'visible'=>false),
			array('name'=>_M('Customer Name'), 'type'=>'text', 'param'=>128, 'required'=>false, 'visible'=>true, 'display_callback'=>array('SCTV_RequirementCommon', 'display_customer_name')),											
			array('name'=>_M('Address'), 'type'=>'text', 'param'=>128, 'required'=>true, 'visible'=>true),
			array('name'=>_M('Street'), 'type'=>'select', 'param'=>array('SCTV_Street'=>'Name'), 'required'=>false, 'visible'=>true, 'display_callback'=>array('SCTV_RequirementCommon', 'display_street')),
			array('name'=>_M('District'), 'type'=>'commondata', 'param'=>array('Countries/VN/DN'), 'extra'=>true, 'required'=>false, 'visible'=>false),
			array('name'=>_M('Ward'), 'type'=>'commondata', 'param'=>array('Countries/VN/DN', 'District'), 'extra'=>true, 'required'=>false, 'visible'=>false),
			array('name'=>_M('Phone'), 'type'=>'text', 'param'=>64, 'required'=>true, 'visible'=>true),			
			array('name'=>_M('Cable Status'), 'type'=>'checkbox', 'required'=>false, 'visible'=>true, 'extra'=>true, 'display_callback'=>array('SCTV_RequirementCommon', 'display_cable_status'), 'QFfield_callback'=>array('SCTV_RequirementCommon', 'QFfield_cable_status')),			
			array('name'=>_M('Number Of HD'), 'type'=>'integer', 'required'=>false, 'visible'=>true),
			array('name'=>_M('Number Of SD'), 'type'=>'integer', 'required'=>false, 'visible'=>true),
			array('name'=>_M('Internet Package'), 'type'=>'select', 'param'=>array('SCTV_InternetPackage'=>'Name'), 'required'=>false, 'visible'=>true),
			array('name'=>_M('Bundle'), 'type'=>'select', 'param'=>array('SCTV_Bundle'=>'Name'), 'required'=>false, 'visible'=>true),			
			array('name'=>_M('Counselor'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>true, 'visible'=>true),
			array('name'=>_M('Status'), 'type'=>'commondata', 'param'=>array('order_by_key'=>true,'SCTV/Requirement/Status'), 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_RequirementCommon', 'display_status'), 'QFfield_callback'=>array('SCTV_RequirementCommon', 'QFfield_status')),					
			array('name'=>_M('Input Date'), 'type'=>'date', 'required'=>true, 'visible'=>true),
			array('name'=>_M('Input Time'), 'type'=>'time', 'required'=>true, 'visible'=>true),
			array('name'=>_M('Delivery Date'), 'type'=>'date', 'required'=>true, 'visible'=>true),
			array('name'=>_M('Requirement Code'), 'type'=>'calculated', 'param'=>Utils_RecordBrowserCommon::actual_db_type('text', 16), 'required'=>false, 'visible'=>true, 'extra'=>false, 'display_callback'=>array('SCTV_RequirementCommon', 'display_requirement_code')),						
			array('name'=>_M('Note'), 'type'=>'text', 'param'=>128, 'required'=>false, 'visible'=>false),			
			array('name'=>_M('Acceptance Report'), 'type'=>'page_split', 'param'=>3),
			array('name'=>_M('Deployment Date'), 'type'=>'date', 'required'=>false, 'visible'=>false),	
			array('name'=>_M('Deployment Time'), 'type'=>'time', 'required'=>false, 'visible'=>false),
			array('name'=>_M('Acceptance Date'), 'type'=>'date', 'required'=>false, 'visible'=>false),
			array('name'=>_M('Deployment Employee'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>false, 'visible'=>false),
			array('name'=>_M('Deployment Cable Status'), 'type'=>'checkbox', 'required'=>false, 'visible'=>false, 'display_callback'=>array('SCTV_RequirementCommon', 'display_deployment_cable_status'), 'QFfield_callback'=>array('SCTV_RequirementCommon', 'QFfield_deployment_cable_status')),
			array('name'=>_M('Deployment HD'), 'type'=>'integer', 'required'=>false, 'visible'=>false),
			array('name'=>_M('Deployment SD'), 'type'=>'integer', 'required'=>false, 'visible'=>false),
			array('name'=>_M('Deployment Internet Package'), 'type'=>'select', 'param'=>array('SCTV_InternetPackage'=>'Name'), 'required'=>false, 'visible'=>false),
			array('name'=>_M('Deployment Bundle'), 'type'=>'select', 'param'=>array('SCTV_Bundle'=>'Name'), 'required'=>false, 'visible'=>false),
			array('name'=>_M('Deployment Business'), 'type'=>'text', 'param'=>128, 'required'=>false, 'visible'=>false),
			array('name'=>_M('Customer Code'), 'type'=>'text', 'param'=>64, 'required'=>false, 'visible'=>true, 'display_callback'=>array('SCTV_RequirementCommon', 'display_customer_code')),						
			array('name'=>_M('Cable Contract Code'), 'type'=>'text', 'param'=>64, 'required'=>false, 'visible'=>true),			
			array('name'=>_M('Internet Contract Code'), 'type'=>'text', 'param'=>64, 'required'=>false, 'visible'=>true),
			array('name'=>_M('Tap Code'), 'type'=>'text', 'param'=>64, 'required'=>false, 'visible'=>false),
			array('name'=>_M('Lend Wifi'), 'type'=>'checkbox', 'required'=>true, 'visible'=>false),
			array('name'=>_M('Charge'), 'type'=>'integer', 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_RequirementCommon', 'display_charge')),			
			array('name'=>_M('Secondary Counselor'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>false, 'visible'=>false),
			array('name'=>_M('Secondary HD'), 'type'=>'integer', 'required'=>false, 'visible'=>false),
			array('name'=>_M('Secondary SD'), 'type'=>'integer', 'required'=>false, 'visible'=>false),
			array('name'=>_M('Secondary Internet Package'), 'type'=>'select', 'param'=>array('SCTV_InternetPackage'=>'Name'), 'required'=>false, 'visible'=>false)			
		);
		
		Utils_RecordBrowserCommon::install_new_recordset('SCTV_Requirement', $fields);
		Utils_RecordBrowserCommon::register_processing_callback('SCTV_Requirement', array('SCTV_RequirementCommon', 'process_request'));
		Utils_RecordBrowserCommon::set_caption('SCTV_Requirement', _M('Requirement'));
		Utils_RecordBrowserCommon::add_default_access('SCTV_Requirement');		
		Utils_AttachmentCommon::new_addon('SCTV_Requirement');
		
		$StatusHistoryFields = array(
			array('name'=>_M('Requirement'), 'type'=>'select', 'param'=>array('SCTV_Requirement'=>'Customer Name'), 'required'=>true, 'visible'=>false),
			array('name'=>_M('Date Time'), 'type'=>'timestamp', 'required'=>true, 'visible'=>true),						
			array('name'=>_M('Employee'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>true, 'visible'=>true),
			array('name'=>_M('Status'), 'type'=>'commondata', 'param'=>array('order_by_key'=>true,'SCTV/Requirement/Status'), 'required'=>true, 'visible'=>true),											
			array('name'=>_M('Note'), 'type'=>'text', 'param'=>128, 'required'=>false, 'visible'=>true)
		);
		
		Utils_RecordBrowserCommon::install_new_recordset('SCTV_StatusHistory', $StatusHistoryFields);
		Utils_RecordBrowserCommon::set_caption('SCTV_StatusHistory', _M('Status History'));
		Utils_RecordBrowserCommon::add_default_access('SCTV_StatusHistory');
		
		Utils_RecordBrowserCommon::new_addon('SCTV_Requirement', 'SCTV/Requirement', 'requirement_status_history_addon', _M('Status History'));
		
		/*
		$DeliveryDateHistoryFields = array(
			array('name'=>_M('Requirement'), 'type'=>'select', 'param'=>array('SCTV_Requirement'=>'Customer Name'), 'required'=>true, 'visible'=>false),
			array('name'=>_M('Date Time'), 'type'=>'timestamp', 'required'=>true, 'visible'=>true),						
			array('name'=>_M('Employee'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>true, 'visible'=>true),
			array('name'=>_M('Delivery Date'), 'type'=>'date', 'required'=>true, 'visible'=>true),											
			array('name'=>_M('Note'), 'type'=>'text', 'param'=>128, 'required'=>false, 'visible'=>true)
		);
		
		Utils_RecordBrowserCommon::install_new_recordset('SCTV_DeliveryDateHistory', $DeliveryDateHistoryFields);
		Utils_RecordBrowserCommon::set_caption('SCTV_DeliveryDateHistory', _M('Delivery Date History'));
		Utils_RecordBrowserCommon::add_default_access('SCTV_DeliveryDateHistory');
		
		Utils_RecordBrowserCommon::new_addon('SCTV_Requirement', 'SCTV/Requirement', 'requirement_delivery_date_history_addon', _M('Delivery Date History'));
		*/
		return true; // Return true on success and false on failure
	}
 
    public function uninstall() { // Here you can place uninstallation process for the module
    	//Utils_RecordBrowserCommon::unregister_processing_callback('SCTV_Requirement', array('SCTV_RequirementCommon', 'process_request'));
		//Base_ThemeCommon::uninstall_default_theme($this->get_type());
		//Utils_RecordBrowserCommon::uninstall_recordset('SCTV_Requirement');
	
		//Utils_CommonDataCommon::remove('SCTV/Requirement/Status');
		//Utils_CommonDataCommon::remove('SCTV/Requirement/Todo');
		
		//Utils_RecordBrowserCommon::uninstall_recordset('SCTV_StatusHistory');
		//Utils_RecordBrowserCommon::uninstall_recordset('SCTV_DeliveryDateHistory');
		return true;
    }
 
 	public function requires($v) {
		return array(
			array('name'=>'Utils/RecordBrowser', 'version'=>0),
			array('name'=>'Utils/Attachment', 'version'=>0),
			array('name'=>'CRM/Common', 'version'=>0),
			array('name'=>'Base/Lang', 'version'=>0),
			array('name'=>'Base/Acl', 'version'=>0),
			array('name'=>'Data/Countries', 'version'=>0)
		);
	}
	
    public function info() { // Returns basic information about the module which will be available in the epesi Main Setup
 
        return array( 'Author'=>'Pham Huu Le Quoc Phuc',
            'License'=>'SCTV',
                     'Description'=>'Requirement');
 
    }
 
    public function simple_setup() { // Indicates if this module should be visible on the module list in Main Setup's simple view
 
        return array('package' => __('Requirement'), 'version'=>'1.0'); // - now the module will be visible as "HelloWorld" in simple_view
 
    }

 
    public function version() { // Return version name of the module
 
        return array('1.1');
 
    }
}
 
?>